home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / fpl70.lha / src / frontend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  6.7 KB  |  224 lines

  1. /******************************************************************************
  2.  *                   FREXX PROGRAMMING LANGUAGE                  *
  3.  ******************************************************************************
  4.  
  5.  frontend.c
  6.  
  7.  All frontend functions.
  8.  
  9.  *****************************************************************************/
  10.  
  11. /************************************************************************
  12.  *                                                                      *
  13.  * fpl.library - A run time library interpreting script langauge.       *
  14.  * Copyright (C) 1992, 1993 FrexxWare                                   *
  15.  * Author: Daniel Stenberg                                              *
  16.  *                                                                      *
  17.  * This program is free software; you can redistribute it and/or modify *
  18.  * it under the terms of the GNU General Public License as published by *
  19.  * the Free Software Foundation; either version 2, or (at your option)  *
  20.  * any later version.                                                   *
  21.  *                                                                      *
  22.  * This program is distributed in the hope that it will be useful,      *
  23.  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
  24.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
  25.  * GNU General Public License for more details.                         *
  26.  *                                                                      *
  27.  * You should have received a copy of the GNU General Public License    *
  28.  * along with this program; if not, write to the Free Software          *
  29.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *
  30.  *                                                                      *
  31.  * Daniel Stenberg                                                      *
  32.  * Birger Jarlsgatan 93b 3tr                                            *
  33.  * 113 56 Stockholm                                                     *
  34.  * Sweden                                                               *
  35.  *                                                                      *
  36.  * FidoNet 2:201/328      email: dast@sth.frontec.se                    *
  37.  *                                                                      *
  38.  ************************************************************************/
  39.  
  40. #if defined(AMIGA)
  41. #include <exec/types.h>
  42. #include <proto/exec.h>
  43. #elif defined(UNIX)
  44. #include <sys/types.h>
  45. #endif
  46.  
  47. #include "script.h"
  48. #include <stdio.h>
  49.  
  50. #if 0
  51.  
  52. /************************************************************************
  53.  *
  54.  * fplCallFunction();
  55.  *
  56.  * Calls the specified function with the data found in a standard struct
  57.  * fplArgument!
  58.  *
  59.  ****/
  60.  
  61. ReturnCode PREFIX fplCallFunction(AREG(0) struct Data *scr,
  62.                   AREG(1) char *funcname,
  63.                   DREG(0) long argc,
  64.                   AREG(2) void **argv,
  65.                   AREG(3) char *format,
  66.                   AREG(4) unsigned long *tags) /* no such yet! */
  67. {
  68.   ReturnCode ret;
  69.   struct Identifier *ident;
  70.   struct fplMsg *msg;
  71.   struct fplStr *string;
  72.   int i=0;
  73.   if(!scr || !funcname || !*funcname || !arg)
  74.     /* prevent a lot of illegal inputs! */
  75.     return(FPLERR_ILLEGAL_ANCHOR);
  76.  
  77.   ret=GetIdentifier(scr, funcname, &ident); /* get identifier struct */
  78.  
  79.   if(!(scr->flags&FPLDATA_ALLFUNCTIONS) && ret)
  80.     return(ret);
  81.  
  82.   GETMEM(pass, sizeof(struct fplArgument));
  83.   pass->name=funcname;
  84.   pass->ID=ident->data.external.ID;
  85.   pass->funcdata=ident->data.external.data;
  86.   pass->key=scr;
  87.   pass->format=format;
  88.  
  89.   for(i=0; i<argc; i++) {
  90.     if(UPPER(format[i])==FPL_STRARG) {
  91.       
  92.     }
  93.   }
  94.  
  95.   CALL(CallFunction(scr, arg, ident)); /* call the function! */
  96.  
  97.   FREE(pass);
  98.  
  99.   /* Since we can't receive any return code the proper way, we remove
  100.      all pending return code messages! */
  101.  
  102.   do {
  103.     GetMessage(scr, FPLMSG_RETURN_INT, &msg);
  104.     if(msg) {
  105.       if(!i++)
  106.     scr->ret=(long)msg->message[0]; /* set return code to first int found */
  107.       DeleteMessage(scr, msg);
  108.     }
  109.   } while(msg);
  110.  
  111.   do {
  112.     GetMessage(scr, FPLMSG_RETURN_STRING, &msg);
  113.     if(msg) {
  114.       FREE(msg->message[0]); /* delete the returned string! */
  115.       DeleteMessage(scr, msg);
  116.     }
  117.   } while(msg);
  118.  
  119.   return(FPL_OK);
  120. }
  121.  
  122. #endif
  123.  
  124. /***************************************************************************
  125.  *
  126.  * fplGetErrorMsg()
  127.  *
  128.  * Returns a char pointer to an error message to the error given as argument.
  129.  *
  130.  ******/
  131.  
  132. char * PREFIX fplGetErrorMsg(AREG(0) struct Data *scr,
  133.                  DREG(0) long error,
  134.                  AREG(1) char *buffer)
  135. {
  136.   /* All FPL error messages. */
  137.   static const char *errors[]={
  138.     "Couldn't open dos.library V33+",
  139.     "Division by zero",
  140.     "Illegal anchor",
  141.     "Illegal array:",   /* */
  142.     "Illegal assign",
  143.     "Illegal break",
  144.     "Illegal condition operator",
  145.     "Illegal continue",
  146.     "Illegal declaration",
  147.     "Illegal parameter",
  148.     "Illegal pre operation",
  149.     "Illegal prototype",
  150.     "Illegal resize",
  151.     "Illegal statement",
  152.     "Illegal variable type",
  153.     "Internal",
  154.     "Function not found:", /* */
  155.     "Missing apostrophe",
  156.     "Missing argument",
  157.     "Missing brace",
  158.     "Missing bracket",
  159.     "Missing operand",
  160.     "Missing parentheses",
  161.     "Missing semicolon",
  162.     "Incomplete statement",
  163.     "File",
  164.     "Out of memory",
  165.     "Parameter out of range",
  166.     "Out of stack space",
  167.     "Program stopped",
  168.     "Read only violation:", /* */
  169.     "Syntax",
  170.     "Unbalanced comment",
  171.     "Unexpected end of program",
  172.     "Unmatched brace",
  173.     "Identifier not found:",  /* */
  174.     "Identifier already used:", /* */
  175.  
  176.     "Missing colon",   /* from version 7 */
  177.     "Missing 'while'", /* from version 7 */
  178.     
  179.     "Unknown" /* MUST be the last member */
  180.     };
  181.  
  182.   char len;
  183.   if(!scr || !buffer)
  184.     return(NULL);
  185.   strcpy(buffer, errors[(error>FPL_EXIT_OK && error<FPLERR_UNKNOWN_ERROR)?
  186.             (error-2):(FPLERR_UNKNOWN_ERROR-1)]);
  187.   len=strlen(buffer);
  188.   if(buffer[len-1]==':') {
  189.     /* Add " <buffer> ", but avoid sprintf() */
  190.     strcat(buffer, " \"");
  191.     strcat(buffer, scr->buf);
  192.     strcat(buffer, "\"");
  193.   }
  194.   strcat(buffer, " error!");
  195.   return(buffer);
  196. }
  197.  
  198. #ifdef AMIGA
  199. long PREFIX fplOpenLib(AREG(0) struct Data *scr,
  200.                        AREG(1) char *name,   /* funclib name */
  201.                        DREG(0) long version, /* version number required */
  202.                        DREG(1) long flags)
  203. {
  204.   long retval;
  205.   ReturnCode ret;
  206.   CALL(OpenLib(scr, name, version, &retval, (unsigned char)flags));
  207.   if(retval)
  208.     return -retval;
  209.   return FPL_OK;
  210. }
  211.  
  212. long PREFIX fplCloseLib(AREG(0) struct Data *scr,
  213.                         AREG(1) char *name, /* funclib name */
  214.                         DREG(0) long force) /* boolean force close! */
  215. {
  216.   long retval;
  217.   ReturnCode ret;
  218.   CALL(CloseLib(scr, name, FPLLIB_FORCE, &retval));
  219.   if(retval)
  220.     return -retval;
  221.   return FPL_OK;
  222. }
  223. #endif
  224.